package edu.ucsd.cs110.mycity.model.data;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.widget.LinearLayout;
import android.widget.ToggleButton;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;

import edu.ucsd.cs110.mycity.MyOverlay;

public class Favorite extends MyOverlay {

	private Long key;
	private String name;
	private String description;
	private GeoPoint point;
	private boolean visibility;
	private Context mContext;
	private ToggleButton setVisibility;
	private LinearLayout lila;
	private AlertDialog.Builder alert;
	
	public Favorite(Drawable defaultMarker, MapView mapView) {
		super(defaultMarker, mapView);
		mContext = mapView.getContext();
		visibility = false;
	}

	@Override
	protected boolean onBalloonTap(int index, OverlayItem item) {
		setVisibility = new ToggleButton(mContext);
		setVisibility.setTextOn("Visible to all");
		setVisibility.setTextOff("Visible to buddies only");
		setVisibility.setChecked(visibility);
		lila = new LinearLayout(mContext);
		lila.setOrientation(1); //1 is for vertical orientation
		lila.addView(setVisibility);
		alert = new AlertDialog.Builder(mContext);
		alert.setTitle("Favorite Settings");
		alert.setView(lila);
		alert.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				Favorite.this.setVisible(setVisibility.isChecked());
				FavoritesModel.save(Favorite.this);
				alert.setView(null);
			}

		});
		alert.setNeutralButton("Delete", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				FavoritesModel.delete(Favorite.this);
			}
		});
		alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
				
			@Override
			public void onClick(DialogInterface dialog, int which) {
				alert.setView(null);
			}
		});
		alert.show();
		return true;
	}

	public void save() {
		
	}
	
	public void setVisible(boolean visibility) {
		this.visibility = visibility;
	}

	public boolean isVisible() {
		return visibility;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public GeoPoint getPoint() {
		return point;
	}

	public void setPoint(GeoPoint point) {
		this.point = point;
	}

	public Long getKey() {
		return key;
	}

	public void setKey(Long key) {
		this.key = key;
	}
	
}
